﻿/*
Commerce by Onex – eCommerce software platform (www.ecommerce.byonex.com)
Copyright (C) 2008-2010 by Onex Group

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 */
using System;
using System.Collections.Generic;
using System.Text;

namespace ShopModel
{
    #region ENUMS

    public enum OrderedProductStatus
    {
        Missing = 1,
        OK = 2,
        Canceled = 3,
        Returned = 4
    }

    #endregion
    
    /// <summary>
    /// Klasa przechowująca informacje o zmówionym produkcie (Class storing information about ordered product)
    /// </summary>
    public class ProductBatch
    {
        #region VARIBLES

        private int productId;
        private int deliveryId;
        private string productName;
        private string categoryName;
        private DateTime deliveryDate;
        private decimal price;
        private decimal cost;
        private int count;
        private int availableCount;
        private decimal vatRateValue;
        private OrderedProductStatus status;
        private decimal discount;
        private int reservedCount;

        #endregion

        #region CONSTRUCTORS

        public ProductBatch()
        {
            productId = -1;
            deliveryId = -1;
            productName = string.Empty;
            categoryName = string.Empty;
            deliveryDate = DateTime.MinValue;
            price = -1m;
            cost = -1m;
            count = -1;
            availableCount = -1;
        }

        public ProductBatch(int ProductID, string ProductName, int DeliveryID, decimal PriceBrutto, decimal CostBrutto, int AvailableCount, int Count, decimal VatRateValue)
        {
            productId = ProductID;
            deliveryId = DeliveryID;
            productName = ProductName;
            categoryName = string.Empty;
            deliveryDate = DateTime.MinValue;
            price = PriceBrutto;
            cost = CostBrutto;
            count = Count;
            availableCount = AvailableCount;
            vatRateValue = VatRateValue;
        }

        public ProductBatch(int ProductID, string ProductName, int DeliveryID, decimal PriceBrutto, decimal CostBrutto, int AvailableCount, int Count, decimal VatRateValue,decimal Discount)
        {
            productId = ProductID;
            deliveryId = DeliveryID;
            productName = ProductName;
            categoryName = string.Empty;
            deliveryDate = DateTime.MinValue;
            price = PriceBrutto;
            cost = CostBrutto;
            count = Count;
            availableCount = AvailableCount;
            vatRateValue = VatRateValue;
            discount = Discount;
        }

        #endregion

        #region FIELDS

        public int ProductId
        {
            get { return productId; }
            set { productId = value; }
        }

        public int DeliveryId
        {
            get { return deliveryId; }
            set { deliveryId = value; }
        }

        public string ProductName
        {
            get { return productName; }
            set { productName = value; }
        }

        public string CategoryName
        {
            get { return categoryName; }
            set { categoryName = value; }
        }

        public DateTime DeliveryDate
        {
            get { return deliveryDate; }
            set { deliveryDate = value; }
        }

        public decimal PriceBrutto
        {
            get { return price-discount; }
            set { price = value; }
        }

        public decimal PriceNetto
        {
            get { return decimal.Round((price - discount) / (1 + vatRateValue), 2); }
            set { price = decimal.Round(value * (1 + vatRateValue), 2); }
        }

        public decimal DiscountBrutto
        {
            get { return discount; }
            set { discount = value; }
        }

        public decimal DiscountNetto
        {
            get { return decimal.Round(discount / (1 + vatRateValue), 2); }
            set { discount = decimal.Round(value * (1 + vatRateValue), 2); }
        }

        public decimal OrgPriceBrutto
        {
            get { return price; }
            set { price = value; }
        }

        public decimal OrgPriceNetto
        {
            get { return decimal.Round(price / (1 + vatRateValue), 2); }
            set { price = decimal.Round(value * (1 + vatRateValue), 2); }
        }

        public decimal CostBrutto
        {
            get { return cost; }
            set { cost = value; }
        }

        public decimal CostNetto
        {
            get { return decimal.Round(cost / (1 + vatRateValue), 2); }
            set { cost = decimal.Round(value * (1 + vatRateValue), 2); }
        }

        public int Count
        {
            get { return count; }
            set { count = value; }
        }

        public int AvailableCount
        {
            get { return availableCount; }
            set { availableCount = value; }
        }

        public decimal ProfitBrutto
        {
            get
            {
                return price - cost;
            }
        }

        public decimal ProfitNetto
        {
            get
            {
                return PriceNetto - CostNetto;
            }
        }

        public decimal VatRateValue
        {
            get { return vatRateValue; }
            set { vatRateValue = value; }
        }

        public OrderedProductStatus Status
        {
            get
            { return status; }
            set
            { status = value; }
        }


        public int ReservedCount
        {
            get { return reservedCount; }
            set { reservedCount = value; }
        }

        public int TotalCount
        {
            get { return reservedCount+availableCount; }
        }


        #endregion

        #region ENUMS


        public enum SortExpresion
        {
            ProductId,
            DeliveryId,
            ProductName,
            Available,
            Count,
            PriceNetto,
            Cost,
            DeliveryDate,
            CategoryName,
        }

        #endregion
    }
}
